package dao;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import model.Estado;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.MemcachedClient;
import exceptions.ConexaoException;

public class MemcachedDao {
	
	EstadoDao ed = new EstadoDao();
	Estado e = new Estado();
	List<Estado>lista = new ArrayList<Estado>();
	
public Collection getLista() throws SQLException, ConexaoException, ClassNotFoundException, IOException {
		
		Estado e = new Estado();
		Collection listaMemcached = new ArrayList<Estado>();
		
		MemcachedClient client =new  MemcachedClient(AddrUtil.getAddresses("localhost:11211"));
	
		Collection noCache = (Collection) client.get("server1");
		listaMemcached.add(noCache);
		
		 return listaMemcached;
		
}
	
	
public Estado getAllEstado() throws IOException, ClassNotFoundException, SQLException {
	
    MemcachedClient client =new  MemcachedClient(AddrUtil.getAddresses("localhost:11211"));

	Estado noCache =(Estado) client.get("server1");
    
	if(noCache!=null){
		
		return noCache;
		
	}if (noCache==null){
			String nome = null;		
			e= (Estado) ed.PesquisarPorNome(nome);
			client.set("server1", 60, e);
			
	}
		return noCache;
   /*
    
    		(List<estado>) MyCache.getInstance().get("AllProducts");
    if(estados != null) {
          return products;
    }
    products = getAllProductsFromDB()
    if(products) {
          MyCache.getInstance().put("AllProducts", 3600, customer);
    }
    return products;
}
	*/
	/*
		public Estado getAllEstado() throws IOException, ClassNotFoundException, SQLException {
			
		    MemcachedClient client =new  MemcachedClient(AddrUtil.getAddresses("localhost:11211"));

			Estado noCache =(Estado) client.get("server1");
		    
			if(noCache!=null){
				
				return noCache;
				
			}if (noCache==null){
					String nome = null;		
					e= (Estado) ed.PesquisarPorNome(nome);
					client.set("server1", 60, e);
					
			}
				return noCache;
	
}	
*/
}
}
